home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / sthing.com / STHING.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-10-28  |  15.9 KB  |  470 lines

  1. ;STHING.ASM - low level interface to Speech Thing SmoothTalker TSR
  2.  
  3. ;Written 10/90, Kim Kokkonen, TurboPower Software
  4. ;Copyright (C) 1990, TurboPower Software. All rights reserved.
  5.  
  6. DATA    SEGMENT BYTE PUBLIC
  7.  
  8. ;Order corresponds to link order given by Pascal declarations
  9.         EXTRN   StAllocFromHeap : BYTE  ;1 to allocate from heap
  10.         EXTRN   SpeechPtr : DWORD       ;Entry point for SPEECHVx
  11.         EXTRN   lUnknown : WORD         ;??
  12.         EXTRN   lTone : WORD            ;Last values for Tone, etc.
  13.         EXTRN   lVolume : WORD
  14.         EXTRN   lPitch : WORD
  15.         EXTRN   lSpeed : WORD
  16.         EXTRN   Int21Err : WORD         ;Error value stored by int 21 ISR
  17.         EXTRN   Have21 : BYTE           ;True when we control int 7E
  18.         EXTRN   Have7E : BYTE           ;True when we control int 21
  19.         EXTRN   Loaded : BYTE           ;True if SPEECHVx loaded
  20.         EXTRN   SaveSP : WORD           ;Keep SPEECHVx from corrupting stack
  21.  
  22. ;lUnknown may take on values of 0 or 1, but it doesn't seem to make
  23. ;  a difference
  24.  
  25. DATA    ENDS
  26.  
  27. CODE    SEGMENT BYTE PUBLIC
  28.  
  29.         ASSUME  CS:CODE, DS:DATA
  30.  
  31.         PUBLIC  StInit, StSetParams, StSpeak
  32.         PUBLIC  StSetPort, StSetLptPort
  33.         PUBLIC  StTextToPhonetic, StPhoneticSpeak
  34.         PUBLIC  StInitDict, StInsertDict, StRemoveDict, StDumpDict
  35.         PUBLIC  StGrabInt7E, StRestoreInt7E
  36.         PUBLIC  StGrabInt21, StRestoreInt21
  37.         PUBLIC  StUnload
  38.  
  39.         EXTRN   AllocSeg : NEAR         ;called in int 21 to allocate memory
  40.  
  41. ;Convenient equates and macros
  42. ofst            EQU     (WORD PTR 0)
  43. segm            EQU     (WORD PTR 2)
  44.  
  45. ;-----------------------------------------------------------------------
  46. ;Int 21 control
  47.         Old21   DD      0
  48.  
  49. ;-----------------------------------------------------------------------
  50. ;procedure New21
  51. ;
  52. New21           PROC FAR
  53.         STI                             ;Allow other interrupts
  54.         CMP     AH,48h                  ;DOS alloc call?
  55.         JZ      NewAlloc                ;We'll handle it
  56.         CMP     AH,49h                  ;DOS dealloc call?
  57.         JZ      NewDealloc              ;We'll handle it
  58.         CLI                             ;Interrupts back off
  59.         JMP     CS:Old21                ;Let DOS handle it
  60. NewAlloc:
  61.         PUSH    CX                      ;Save registers
  62.         PUSH    DX
  63.         PUSH    SI
  64.         PUSH    DI
  65.         PUSH    DS
  66.         PUSH    ES
  67.         MOV     AX,SEG DATA             ;Set up Turbo data segment
  68.         MOV     DS,AX
  69.         PUSH    BX                      ;Paragraphs to allocate
  70.         CALL    AllocSeg                ;Let Turbo allocate from heap
  71.         CLC                             ;Prepare for success
  72.         OR      AX,AX                   ;Success?
  73.         JNZ     NewAllocDone            ;Jump if so
  74.         MOV     AX,8                    ;Out of memory error
  75.         MOV     Int21Err,AX
  76.         XOR     BX,BX                   ;No memory free
  77.         STC                             ;Return carry set
  78. NewAllocDone:
  79.         POP     ES
  80.         POP     DS
  81.         POP     DI
  82.         POP     SI
  83.         POP     DX
  84.         POP     CX
  85.         RET     2
  86.  
  87. NewDealloc:
  88.         XOR     AX,AX                   ;Return success, but don't do anything
  89.         CLC
  90.         RET     2
  91. New21           ENDP
  92.  
  93. ;-----------------------------------------------------------------------
  94. ;procedure StGrabInt21;
  95. ;
  96. StGrabInt21     PROC FAR
  97.         CMP     Have21,0                ;Do we currently have int 21?
  98.         JNZ     Grab21Done              ;Jump if so
  99.         MOV     AX,3521h
  100.         INT     21h                     ;Get interrupt 21 vector
  101.         MOV     Old21.ofst,BX           ;Save it
  102.         MOV     Old21.segm,ES
  103.         PUSH    DS                      ;Save DS
  104.         PUSH    CS
  105.         POP     DS
  106.         MOV     DX,OFFSET New21         ;DS:DX -> New21
  107.         MOV     AX,2521h
  108.         INT     21h                     ;Take over int 21
  109.         POP     DS
  110.         MOV     Have21,1                ;Mark that we have int 21
  111. Grab21Done:
  112.         RET
  113. StGrabInt21     ENDP
  114.  
  115. ;-----------------------------------------------------------------------
  116. ;procedure StRestoreInt21;
  117. ;
  118. StRestoreInt21  PROC FAR
  119.         CMP     Have21,0                ;Do we currently have int 21?
  120.         JZ      Restore21Done           ;Jump if not
  121.         PUSH    DS                      ;Save DS
  122.         MOV     DX,Old21.ofst
  123.         MOV     DS,Old21.segm           ;DS:DX -> old int 21
  124.         MOV     AX,2521h
  125.         INT     21h                     ;Restore int 21
  126.         POP     DS
  127.         MOV     Have21,0
  128. Restore21Done:
  129.         RET
  130. StRestoreInt21  ENDP
  131.  
  132. ;-----------------------------------------------------------------------
  133. ;Important note: SPEECHVx sometimes trashes the BP and SP registers
  134. ;                the following code carefully saves and restores them
  135.  
  136. ;-----------------------------------------------------------------------
  137. ;procedure StInit;
  138. ;
  139. StInit          PROC FAR
  140.         PUSH    BP
  141.         MOV     SaveSP,SP
  142.         MOV     AL,1                    ;function 1
  143.         CALL    SpeechPtr
  144.         MOV     SP,SaveSP
  145.         POP     BP
  146.         RET
  147. StInit          ENDP
  148.  
  149. ;-----------------------------------------------------------------------
  150. ;procedure StSetParams(Tone, Volume, Pitch, Speed : Word);
  151. StSetParams     PROC FAR
  152.         CMP     Loaded,0                ;get out if SPEECHVx not installed
  153.         JZ      SetDone
  154.         PUSH    BP
  155.         MOV     BP,SP
  156.         MOV     SaveSP,BP
  157.         MOV     AX,[lUnknown]           ;AX=lUnknown
  158.         PUSH    AX
  159.         MOV     AX,[BP+12]              ;AX=Tone
  160.         MOV     [lTone],AX
  161.         PUSH    AX
  162.         MOV     AX,[BP+10]              ;AX=Volume
  163.         MOV     [lVolume],AX
  164.         PUSH    AX
  165.         MOV     AX,[BP+8]               ;AX=Pitch
  166.         MOV     [lPitch],AX
  167.         PUSH    AX
  168.         MOV     AX,[BP+6]               ;AX=Speed
  169.         MOV     [lSpeed],AX
  170.         PUSH    AX
  171.         MOV     AL,2                    ;function 2
  172.         CALL    SpeechPtr
  173.         MOV     SP,SaveSP
  174.         POP     BP
  175. SetDone:
  176.         RET     8
  177. StSetParams     ENDP
  178.  
  179. ;-----------------------------------------------------------------------
  180. ;procedure StSetPort(Port : Word);
  181. StSetPort       PROC FAR
  182.         CMP     Loaded,0                ;get out if SPEECHVx not installed
  183.         JZ      SetPortDone
  184.         MOV     BX,SP
  185.         MOV     DX,SS:[BX+4]            ;DX=Port
  186.         XOR     AX,AX
  187.         MOV     ES,AX                   ;ES=0
  188.         OR      DX,DX                   ;0 means default port of LPT1
  189.         JNZ     SpecificPort
  190.         MOV     DX,ES:[0408h]           ;Get port from BIOS LPT1 location
  191. SpecificPort:
  192.         MOV     ES:[4*066h],DX          ;Store port in int 66h
  193. SetPortDone:
  194.         RET     2
  195. StSetPort       ENDP
  196.  
  197. ;-----------------------------------------------------------------------
  198. ;procedure StSetLptPort(LPTNumber : Byte);
  199. StSetLptPort    PROC FAR
  200.         CMP     Loaded,0                ;get out if SPEECHVx not installed
  201.         JZ      SetLptPortDone
  202.         MOV     BX,SP
  203.         MOV     BL,SS:[BX+4]            ;BL=LPTNumber
  204.         OR      BL,BL
  205.         JZ      SetLptPortDone          ;Jump if LPTNumber<1
  206.         CMP     BL,3
  207.         JA      SetLptPortDone          ;Jump if LPTNumber>3
  208.         XOR     AX,AX
  209.         MOV     ES,AX                   ;ES=0
  210.         MOV     BH,AL
  211.         DEC     BX                      ;BX=0..2
  212.         SHL     BX,1                    ;Word offset
  213.         ADD     BX,408h                 ;ES:BX -> BIOS port number
  214.         MOV     DX,ES:[BX]              ;Get port from BIOS location
  215.         MOV     ES:[4*066h],DX          ;Store port in int 66h
  216. SetLptPortDone:
  217.         RET     2
  218. StSetLptPort    ENDP
  219.  
  220. ;-----------------------------------------------------------------------
  221. ;procedure StSpeak(St : string);
  222. ;
  223. StSpeak         PROC FAR
  224.         CMP     Loaded,0                ;get out if SPEECHVx not installed
  225.         JZ      SpeakDone
  226.         PUSH    BP
  227.         MOV     BP,SP
  228.         MOV     SaveSP,BP
  229.         LES     DI,[BP+6]               ;ES:DI -> St
  230.         PUSH    ES
  231.         PUSH    DI
  232.         MOV     AL,7                    ;function 7
  233.         CALL    SpeechPtr
  234.         MOV     SP,SaveSP
  235.         POP     BP
  236. SpeakDone:
  237.         RET     4
  238. StSpeak         ENDP
  239.  
  240. ;-----------------------------------------------------------------------
  241. ;procedure StTextToPhonetic(TextSt : string; var PhonSt : string);
  242. ;
  243. StTextToPhonetic PROC FAR
  244.         CMP     Loaded,0                ;get out if SPEECHVx not installed
  245.         JZ      TextToPhoneticDone
  246.         PUSH    BP
  247.         MOV     BP,SP
  248.         MOV     SaveSP,BP
  249.         LES     DI,[BP+10]              ;ES:DI -> TextSt
  250.         PUSH    ES
  251.         PUSH    DI
  252.         LES     DI,[BP+6]               ;ES:DI -> PhonSt[0]
  253.         PUSH    ES
  254.         PUSH    DI
  255.         MOV     AX,1
  256.         PUSH    AX                      ;PUSH 1
  257.         DEC     AX                      ;function 0
  258.         CALL    SpeechPtr               ;returns AX?
  259.         MOV     SP,SaveSP
  260.         POP     BP
  261. TextToPhoneticDone:
  262.         RET     8
  263. StTextToPhonetic ENDP
  264.  
  265. ;-----------------------------------------------------------------------
  266. ;procedure StPhoneticSpeak(St : string);
  267. ;
  268. StPhoneticSpeak PROC FAR
  269.         CMP     Loaded,0                ;get out if SPEECHVx not installed
  270.         JZ      PhoneticSpeakDone
  271.         PUSH    BP
  272.         MOV     BP,SP
  273.         MOV     SaveSP,BP
  274.         LES     DI,[BP+6]               ;ES:DI -> St
  275.         PUSH    ES
  276.         PUSH    DI
  277.         PUSH    [lTone]                 ;could specify alternate speech params
  278.         PUSH    [lPitch]
  279.         PUSH    [lSpeed]
  280.         PUSH    [lVolume]
  281.         MOV     AX,[lUnknown]
  282.         ADD     AL,8                    ;function 8+lUnknown
  283.         CALL    SpeechPtr
  284.         MOV     SP,SaveSP
  285.         POP     BP
  286. PhoneticSpeakDone:
  287.         RET     4
  288. StPhoneticSpeak ENDP
  289.  
  290. ;-----------------------------------------------------------------------
  291. ;procedure StInitDict(Clear : Boolean);
  292. ;
  293. StInitDict      PROC FAR
  294.         CMP     Loaded,0                ;get out if SPEECHVx not installed
  295.         JZ      InitDictDone
  296.         PUSH    BP
  297.         MOV     BP,SP
  298.         MOV     SaveSP,BP
  299.         MOV     AL,[BP+6]               ;store Clear value
  300.         XOR     AH,AH
  301.         PUSH    AX
  302.         MOV     AL,4                    ;function 4
  303.         CALL    SpeechPtr
  304.         MOV     SP,SaveSP
  305.         POP     BP
  306. InitDictDone:
  307.         RET     2
  308. StInitDict      ENDP
  309.  
  310. ;-----------------------------------------------------------------------
  311. ;function StInsertDict(TextSt : string; PhonSt : string) : Boolean;
  312. ;
  313. StInsertDict    PROC FAR
  314.         XOR     AX,AX                   ;assume False return
  315.         CMP     Loaded,0                ;get out if SPEECHVx not installed
  316.         JZ      InsertDictDone
  317.         CMP     StAllocFromHeap,0       ;allocating from Turbo heap?
  318.         JZ      Insert1                 ;jump if not
  319.         CALL    StGrabInt21             ;grab int 21 temporarily
  320. Insert1:
  321.         MOV     Int21Err,0              ;clear error indicator
  322.         PUSH    BP
  323.         MOV     BP,SP
  324.         MOV     SaveSP,BP
  325.         LES     DI,[BP+10]              ;ES:DI -> TextSt
  326.         PUSH    ES
  327.         PUSH    DI
  328.         LES     DI,[BP+6]               ;ES:DI -> PhonSt
  329.         PUSH    ES
  330.         PUSH    DI
  331.         MOV     AL,3                    ;function 3
  332.         CALL    SpeechPtr
  333.         MOV     SP,SaveSP
  334.         POP     BP
  335.         CALL    StRestoreInt21          ;give back int 21 if we have it
  336.         MOV     AL,1                    ;assume success
  337.         CMP     Int21Err,0              ;error in int 21?
  338.         JZ      InsertDictDone          ;jump if no error
  339.         XOR     AL,AL                   ;return False
  340. InsertDictDone:
  341.         RET     8
  342. StInsertDict    ENDP
  343.  
  344. ;-----------------------------------------------------------------------
  345. ;procedure StRemoveDict(TextSt : string);
  346. ;
  347. StRemoveDict    PROC FAR
  348.         CMP     Loaded,0                ;get out if SPEECHVx not installed
  349.         JZ      RemoveDictDone
  350.         CMP     StAllocFromHeap,0       ;allocating from Turbo heap?
  351.         JZ      Remove1                 ;jump if not
  352.         CALL    StGrabInt21             ;grab int 21 temporarily
  353. Remove1:
  354.         PUSH    BP
  355.         MOV     BP,SP
  356.         MOV     SaveSP,BP
  357.         LES     DI,[BP+6]               ;ES:DI -> TextSt
  358.         PUSH    ES
  359.         PUSH    DI
  360.         MOV     AL,5                    ;function 5
  361.         CALL    SpeechPtr
  362.         MOV     SP,SaveSP
  363.         POP     BP
  364.         CALL    StRestoreInt21          ;give back int 21 if we have it
  365. RemoveDictDone:
  366.         RET     4
  367. StRemoveDict    ENDP
  368.  
  369. ;-----------------------------------------------------------------------
  370. ;procedure StDumpDict(var TextSt : string; var PhonSt : string);
  371. ;
  372. StDumpDict      PROC FAR
  373.         CMP     Loaded,0                ;get out if SPEECHVx not installed
  374.         JZ      DumpDictDone
  375.         PUSH    BP
  376.         MOV     BP,SP
  377.         MOV     SaveSP,BP
  378.         LES     DI,[BP+10]              ;ES:DI -> TextSt
  379.         PUSH    ES
  380.         PUSH    DI
  381.         LES     DI,[BP+6]               ;ES:DI -> PhonSt
  382.         PUSH    ES
  383.         PUSH    DI
  384.         MOV     AL,6                    ;function 6
  385.         CALL    SpeechPtr
  386.         MOV     SP,SaveSP
  387.         POP     BP
  388. DumpDictDone:
  389.         RET     8
  390. StDumpDict    ENDP
  391.  
  392. ;-----------------------------------------------------------------------
  393. ;procedure StUnload;
  394. ;
  395. StUnload        PROC FAR
  396.         CMP     Loaded,0                ;get out if SPEECHVx not installed
  397.         JZ      UnloadDone
  398.         PUSH    BP
  399.         MOV     SaveSP,SP
  400.         MOV     AL,0Bh                  ;function 0B
  401.         CALL    SpeechPtr
  402.         MOV     SP,SaveSP
  403.         POP     BP
  404.         MOV     Loaded,0                ;mark unloaded
  405. UnloadDone:
  406.         RET
  407. StUnload        ENDP
  408.  
  409. ;-----------------------------------------------------------------------
  410. ;Int 7E control
  411.         Old7E   DD      0
  412.  
  413. ;-----------------------------------------------------------------------
  414. ;Software interrupt used by SPEECHV3 to check for key interrupts
  415. ;Ok to change AX,DX,ES
  416. ;Returns AX=0 to continue speech, AX<>0 to halt speech
  417. ;
  418. New7E          PROC   FAR
  419.         XOR    AX,AX
  420.         MOV    ES,AX
  421.         MOV    DL,ES:[041Ah]
  422.         CMP    DL,ES:[041Ch]            ;Keys in keyboard buffer?
  423.         JZ     SpeechContinue           ;Jump if not
  424.         MOV    AL,0FFh                  ;Flag stops speech
  425. SpeechContinue:
  426.         IRET
  427. New7E          ENDP
  428.  
  429. ;-----------------------------------------------------------------------
  430. ;procedure StGrabInt7E;
  431. ;
  432. StGrabInt7E     PROC FAR
  433.         CMP     Have7E,0                ;Do we currently have int 7E?
  434.         JNZ     Grab7EDone              ;Jump if so
  435.         MOV     AX,357Eh
  436.         INT     21h
  437.         MOV     Old7E.ofst,BX
  438.         MOV     Old7E.segm,ES
  439.         PUSH    DS
  440.         PUSH    CS
  441.         POP     DS
  442.         MOV     DX,OFFSET New7E
  443.         MOV     AX,257Eh
  444.         INT     21h
  445.         POP     DS
  446.         MOV     Have7E,1                ;Mark that we have int 7E
  447. Grab7EDone:
  448.         RET
  449. StGrabInt7E     ENDP
  450.  
  451. ;-----------------------------------------------------------------------
  452. ;procedure StRestoreInt7E;
  453. ;
  454. StRestoreInt7E  PROC FAR
  455.         CMP     Have7E,0                ;Do we currently have int 7E?
  456.         JZ      Restore7EDone           ;Jump if not
  457.         PUSH    DS                      ;Save DS
  458.         MOV     DX,Old7E.ofst
  459.         MOV     DS,Old7E.segm           ;DS:DX -> old int 7E
  460.         MOV     AX,257Eh
  461.         INT     21h                     ;Restore int 7E
  462.         POP     DS
  463.         MOV     Have7E,0                ;We no longer have 7E
  464. Restore7EDone:
  465.         RET
  466. StRestoreInt7E  ENDP
  467.  
  468. CODE    ENDS
  469.         END
  470.